
import React from 'react';

export default class DivCom extends React.Component{

  //声明状态
  state = {
    opacity: 1
  }

  //事件的回调
  swi = () => {
    this.setState({
      opacity: this.state.opacity ? 0 : 1
    })
  }

  render(){
    return <div>
      <button onClick={this.swi}>切换</button>
      <div style={{height: 100, background: '#c78', opacity: this.state.opacity, transition: 'opacity 0.5s'}}></div>
    </div>
  }
}